package dynaspring.xml;

import java.io.IOException;
import java.io.StringReader;

import org.springframework.beans.factory.config.BeanDefinition;
import org.springframework.beans.factory.xml.BeanDefinitionParser;
import org.springframework.beans.factory.xml.ParserContext;
import org.w3c.dom.Element;

import dynaspring.LispBeanDefinitionReader;

public class DynaspringCodeParser implements BeanDefinitionParser {

	@Override
	public BeanDefinition parse(Element el, ParserContext ctx) {
		LispBeanDefinitionReader reader = new LispBeanDefinitionReader(ctx.getRegistry());
		String code = el.getTextContent();
		try {
			reader.loadBeanDefinitions(new StringReader(code), null);
		} catch (IOException e) {
			ctx.getReaderContext().error("Error loading code " + code, el, e);
		}
		return null;
	}

}
